using System.ComponentModel.DataAnnotations;

namespace MVCWeekOne.Models
{
    public class LoginViewModel
    {
        [Required(ErrorMessage = "用户名不能为空")]
        [Display(Name = "用户名")]
        public string Username { get; set; } = string.Empty;

        [Required(ErrorMessage = "密码不能为空")]
        [Display(Name = "密码")]
        [DataType(DataType.Password)]
        public string Password { get; set; } = string.Empty;

        [Required(ErrorMessage = "验证码不能为空")]
        [Display(Name = "验证码")]
        [StringLength(4, MinimumLength = 4, ErrorMessage = "验证码必须是4位")]
        public string Captcha { get; set; } = string.Empty;

        [Display(Name = "记住密码")]
        public bool RememberMe { get; set; }
    }

    public class AddUserViewModel
    {
        [Required(ErrorMessage = "用户名不能为空")]
        [Display(Name = "用户名")]
        public string Name { get; set; } = string.Empty;

        [Required(ErrorMessage = "密码不能为空")]
        [Display(Name = "密码")]
        [DataType(DataType.Password)]
        public string Pwd { get; set; } = string.Empty;

        [Required(ErrorMessage = "真实姓名不能为空")]
        [Display(Name = "真实姓名")]
        public string RealName { get; set; } = string.Empty;

        [Required(ErrorMessage = "请选择角色")]
        [Display(Name = "角色")]
        public List<long> RoleIds { get; set; } = new List<long>();
    }

    public class AddRoleViewModel
    {
        [Required(ErrorMessage = "角色名称不能为空")]
        [Display(Name = "角色名称")]
        public string RoleName { get; set; } = string.Empty;

        [Display(Name = "权限")]
        public List<long> PermissionIds { get; set; } = new List<long>();
    }

    public class UpdateRoleViewModel
    {
        public long RoleId { get; set; }

        [Required(ErrorMessage = "角色名称不能为空")]
        [Display(Name = "角色名称")]
        public string RoleName { get; set; } = string.Empty;

        [Display(Name = "权限")]
        public List<long> PermissionIds { get; set; } = new List<long>();
    }

    public class AddPermissionViewModel
    {
        [Required(ErrorMessage = "权限名称不能为空")]
        [Display(Name = "权限名称")]
        public string PermissionName { get; set; } = string.Empty;

        [Display(Name = "权限URL")]
        public string PermissionURL { get; set; } = string.Empty;

        [Display(Name = "父级权限")]
        public int ParentId { get; set; }
    }

    public class UpdatePermissionViewModel
    {
        public long Id { get; set; }

        [Required(ErrorMessage = "权限名称不能为空")]
        [Display(Name = "权限名称")]
        public string PermissionName { get; set; } = string.Empty;

        [Display(Name = "权限URL")]
        public string PermissionURL { get; set; } = string.Empty;

        [Display(Name = "父级权限")]
        public int ParentId { get; set; }
    }

    public class DeleteRoleViewModel
    {
        public long RoleId { get; set; }
    }

    public class DeletePermissionViewModel
    {
        public long PermissionId { get; set; }
    }

    /// <summary>
    /// 生产计划查询视图模型
    /// </summary>
    public class PlanSearchViewModel
    {
        [Display(Name = "页码")]
        public int Index { get; set; } = 1;

        [Display(Name = "页大小")]
        public int Size { get; set; } = 20;

        [Display(Name = "计划单号")]
        public string? PlanCode { get; set; }

        [Display(Name = "备注")]
        public string? Remark { get; set; }

        [Display(Name = "创建人")]
        public string? CreateBy { get; set; }
    }

    /// <summary>
    /// 保存生产计划视图模型
    /// </summary>
    public class SavePlanViewModel
    {
        public int Id { get; set; }

        [Display(Name = "计划单号")]
        public string PlanCode { get; set; } = string.Empty;

        [Required(ErrorMessage = "备注不能为空")]
        [Display(Name = "备注")]
        public string Remark { get; set; } = string.Empty;

        [Display(Name = "计划明细")]
        public List<PlanItemViewModel> Items { get; set; } = new List<PlanItemViewModel>();
    }

    /// <summary>
    /// 计划明细视图模型
    /// </summary>
    public class PlanItemViewModel
    {
        public int Id { get; set; }
        public int PlanId { get; set; }

        [Required(ErrorMessage = "请选择产品")]
        public int ProductId { get; set; }

        public string ProductCode { get; set; } = string.Empty;
        public string ProductName { get; set; } = string.Empty;
        public string Specification { get; set; } = string.Empty;
        public string Unit { get; set; } = string.Empty;

        [Required(ErrorMessage = "计划数量不能为空")]
        [Range(0.01, double.MaxValue, ErrorMessage = "计划数量必须大于0")]
        [Display(Name = "计划数量")]
        public decimal PlannedQuantity { get; set; }

        [Display(Name = "完成数量")]
        public decimal CompletedQuantity { get; set; }

        [Display(Name = "工单编号")]
        public string WorkOrderNumber { get; set; } = string.Empty;
    }

    /// <summary>
    /// 产品搜索视图模型
    /// </summary>
    public class ProductSearchViewModel
    {
        [Display(Name = "页码")]
        public int Index { get; set; } = 1;

        [Display(Name = "页大小")]
        public int Size { get; set; } = 20;

        [Display(Name = "产品编号")]
        public string? ProductCode { get; set; }

        [Display(Name = "产品名称")]
        public string? ProductName { get; set; }
    }

    /// <summary>
    /// 批量删除计划视图模型
    /// </summary>
    public class BatchDeletePlanViewModel
    {
        [Required(ErrorMessage = "请选择要删除的计划")]
        public List<int> PlanIds { get; set; } = new List<int>();
    }

    /// <summary>
    /// 导出计划视图模型
    /// </summary>
    public class ExportPlanViewModel
    {
        public string? PlanCode { get; set; }
        public string? Remark { get; set; }
        public string? CreateBy { get; set; }
        public DateTime? StartDate { get; set; }
        public DateTime? EndDate { get; set; }
    }

    /// <summary>
    /// 保存生产计划请求模型（用于Ajax）
    /// </summary>
    public class SavePlanRequest
    {
        public int Id { get; set; }
        public string? Code { get; set; }
        public string Remark { get; set; } = string.Empty;
        public List<SavePlanItemRequest> Items { get; set; } = new List<SavePlanItemRequest>();
        public List<SavePlanProductRequest> Products { get; set; } = new List<SavePlanProductRequest>();
    }

    /// <summary>
    /// 保存生产计划明细请求模型（用于Ajax）
    /// </summary>
    public class SavePlanItemRequest
    {
        public int Id { get; set; }
        public int PlanId { get; set; }
        
        [Required(ErrorMessage = "产品编号不能为空")]
        public string ProductCode { get; set; } = string.Empty;
        
        [Required(ErrorMessage = "产品名称不能为空")]
        public string ProductName { get; set; } = string.Empty;
        
        public string? Spec { get; set; }
        
        [Range(1, int.MaxValue, ErrorMessage = "数量必须大于0")]
        public int Quantity { get; set; }
        
        public int? DoneQuantity { get; set; }
        
        public string? WorkOrderCode { get; set; }
        
        /// <summary>
        /// 是否删除（用于标识需要删除的明细）
        /// </summary>
        public bool IsDeleted { get; set; }
    }

    /// <summary>
    /// 保存生产计划关联产品请求模型（用于Ajax）
    /// </summary>
    public class SavePlanProductRequest
    {
        public int Id { get; set; }
        public int PlanId { get; set; }
        
        [Required(ErrorMessage = "产品编号不能为空")]
        public string ProductCode { get; set; } = string.Empty;
        
        [Required(ErrorMessage = "产品名称不能为空")]
        public string ProductName { get; set; } = string.Empty;
        
        public string? Spec { get; set; }
        public string? Unit { get; set; }
        public string? Producer { get; set; }
        public DateTime ProductionStartTime { get; set; } = DateTime.Now;
        public DateTime ProductionEndTime { get; set; } = DateTime.Now.AddDays(1);
        
        /// <summary>
        /// 是否从计划中移除该产品（解除关联）
        /// </summary>
        public bool IsRemoved { get; set; }
    }


}
